package com.zzptc.sky.baidudemo.activities;

import android.app.FragmentManager;
import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;

import com.zzptc.sky.baidudemo.R;
import com.zzptc.sky.baidudemo.base.BaseActivity;
import com.zzptc.sky.baidudemo.fragments.SOSFirstFragment;
import com.zzptc.sky.baidudemo.fragments.SOSSecondFragment;
import com.zzptc.sky.baidudemo.fragments.SOSThreeFragment;
import com.zzptc.sky.baidudemo.utils.MyApplication;

public class OneKeySOSActivity extends BaseActivity {

    private Toolbar tool_bar_sos;
    private SOSFirstFragment sosFirstFragment;
    private SOSSecondFragment sosSecondFragment;
    private SOSThreeFragment sosThreeFragment;
    private ImageView iv_info;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_one_key_sos);

        tool_bar_sos = (Toolbar) findViewById(R.id.tool_bar_sos);
        iv_info = (ImageView) findViewById(R.id.iv_info);

        setSupportActionBar(tool_bar_sos);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        sosFirstFragment = new SOSFirstFragment();
        getFragmentManager().beginTransaction().replace(R.id.fl_sos,sosFirstFragment).addToBackStack("sos").commit();

    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_one_key_sos;
    }

    public void toSecondFragment(){
        if (sosSecondFragment == null){
            sosSecondFragment = new SOSSecondFragment();
        }
        getFragmentManager().beginTransaction().replace(R.id.fl_sos,sosSecondFragment).addToBackStack("sos").commit();
        iv_info.setVisibility(View.GONE);
    }

    @Override
    public void onBackPressed() {
        if (getFragmentManager().getBackStackEntryCount() == 1){
            getFragmentManager().popBackStack();
        }else {
            finish();
        }
    }

    public void toThreeFragment(){
        if (sosThreeFragment == null){
            sosThreeFragment = new SOSThreeFragment();
        }
        //getFragmentManager().popBackStack("sos", FragmentManager.POP_BACK_STACK_INCLUSIVE);
        getFragmentManager().beginTransaction().replace(R.id.fl_sos,sosThreeFragment).addToBackStack("sos").commit();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        AnimationDrawable animationDrawable = (AnimationDrawable) sosThreeFragment.getThisView().findViewById(R.id.iv_animation).getBackground();
        animationDrawable.start();
    }
}
